<!-- Veljko Jovanovic -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<script type="text/javascript" src="jquery.js"></script>

<script language="javascript" type="text/javascript">
<!--
var idPrijave;


function oceni(idPok, idKkor)
 {
	 <!-- if(idKor==0) return;
	 if (idPok>0)
	 {
		 $("#podaci").load("oceni.php", { plus:idPok, idKor:idKkor});
	
	 }
	 else 
	 {
		 idPok = 0 - idPok;
		  $("#podaci").load("oceni.php", { minus:idPok, idKor:idKkor});
	  }
}
function prikaziPopUp(id) 
 { 
	$("#popUp").css("visibility","visible");
	idPrijave = id;
 } 
 
 function posaljiPrijavu()
 {
	 $("#popUp").css("visibility","hidden");

	 var url = window.location + '';
	 var poz = url.lastIndexOf('#');
	 if (idPrijave != 0)
	 {	 
	 if (poz>0) url = url.substring(0, poz);
	 url = url + "&prijavljenKomentar="+idPrijave+"#";
	 }
	 tekst = $("#poljeZaPrijavu").val();
 	 $.post("obradaPrijave.php", { adr : url, text : tekst});
 }
 
 function ubaciKomentar(idpok)
 {
	 var komentar = $("#kom").val();
	 $("#komentari").load("salji_bazi.php", { kom:komentar, id:idpok});
 }
 
 function ukloniKomentar(id, idpoklona)
 {
	$("#komentari").load("brisanjeKomentara.php", { idkom:id, idpok:idpoklona}); 
 }
  function ukloniPoklon(idpoklona)
 {
	 $("#strana").load("uklanjanjePoklona.php", { idpok : idpoklona});
 }
// -->
</script> 
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="shortcut icon" href="favicon.ico"></link>
<title>Поклони</title>
<link href="style.css" rel="stylesheet" type="text/css" media="screen" />
</head>

<body id="strana">

<div id="wrapper">
<?php
	
	session_start();
	if (isset($_GET["id"])) $idPoklona=$_GET["id"];
	else $idPoklona = 0;
	
	if (isset($_SESSION["kor"])) $idKorisnika = $_SESSION["idkor"];
	else $idKorisnika = 0;
	
	if (isset($_GET["prijavljenKomentar"])) $prijavljenKomentar = $_GET["prijavljenKomentar"];
	else $prijavljenKomentar = 0;
	
	if (isset($_SESSION["tip"])) $tipKorisnika = $_SESSION["tip"];
	else $tipKorisnika = "N";
	
	include("insert/head.php");
    
	include("konekcija_sa_bazom.php");
	
	if ($idKorisnika !=0 )
	{
		$sql="SELECT * FROM korisnik WHERE idKorisnik = '".$idKorisnika."'";
		$result = mysql_query($sql);
		if ( mysql_num_rows($result) ) $idKorisnika = 0;
	}
	if ($idPoklona!=0) 
	{
	$sql="SELECT * FROM poklon WHERE idPoklon = '".$idPoklona."'";
	$result = mysql_query($sql);
	
	if (mysql_num_rows($result) != 1) {
		$greska = 1;
	}
	else $greska =0;
	if ($greska==0)
	{
	$row = mysql_fetch_array($result);

        $opis = $row['opis'];
	$naziv = $row['naziv'];
	$cena = $row['cena'];
	$plus = $row['brojPluseva'];
	$minus = $row['brojMinusa'];
	
	if (!isset($row['idSlika'])) $idslika = '1';
	else $idSlika = $row['idSlika'];
	
	$sql="SELECT * FROM slika WHERE idSlika = '".$row['idSlika']."'";
	$result = mysql_query($sql);
	$red = mysql_fetch_array($result);
	
	$sql="SELECT * FROM korisnik WHERE idKorisnik = '".$row['idKorisnik']."'";
	$result = mysql_query($sql);
	$redK = mysql_fetch_array($result);
	if (isset($redK['ime'])) $imeK = $redK['ime'];
	}
	}
?>
	
    <div id="content">
    	<div id="content-main">
        	 <?php 
			if ($greska==0)
			{
			echo '<center><img src="phpscripts/prikazisliku.php?id='. $red["idSlika"]. '" style="max-height: 600px; max-width: 400px" /></center></br></br>'; 
			echo "$opis</br></br>";
			}
			else echo "Poklon nije pronadjen. Moguce da je uklonjen."
			?>
        	 
            	<?php 
				if ($greska==0){
					echo '<div id="komentari" class="scroll-container">';
					if ($tipKorisnika=='P') 
					{
						?>
                        <table bgcolor="#DEF7F4">
                        	<tr >
                            <td>
                            <textarea id="kom" cols = "70" rows="3"> 
                            </textarea>
                            </td>
                            </tr>
                            <tr align="right">
                            <td align="right">
                            <a href="#" class="button" onclick ="ubaciKomentar(<?php echo $idPoklona ?>)" style="float:right; font-size:14px; ">Postavi</a>
                     
                
                            </td>
                            </tr>
                            
                        </table>
					<?php
                    }
					
					$sql="SELECT * FROM komentar AS k, komentarpoklona AS kp WHERE k.idKomentar = kp.idKomentar AND kp.idPoklon = $idPoklona ORDER BY k.datumKreiranja DESC";
					$result = mysql_query($sql);
					for ( $i = 0; $i < mysql_num_rows($result); $i++)
					{
						$komentar = mysql_fetch_array($result);
						
						$sql="SELECT * FROM korisnik WHERE idKorisnik = '".$komentar['idKorisnik']."'";
						$korisnici = mysql_query($sql);
						$postavioK = mysql_fetch_array($korisnici);
						
						echo "<table>";
						echo '<tr bgcolor=';
						if ($prijavljenKomentar==$komentar['idKomentar']) echo "#E6AD00";
						else echo "#DEF7F4";
						echo '><td width="600"><div style="background:#FFF"> ';
						if (isset($postavioK['ime'])) echo '<font size = "2"><a href="Profil.php?id='.$postavioK["idKorisnik"].'">'.$postavioK["ime"].'</a>: </font>';
						echo $komentar['sadrzaj']."</div>";
						echo '<p align="right" style="margin:0">'.$komentar['datumKreiranja'];
						if ($tipKorisnika == "A") echo '<input type="button" onclick ='.'"'.'return ukloniKomentar('.$komentar['idKomentar'].','.$idPoklona.')" id="btnSearch" class="button" value="Ukloni" style="padding-bottom:1px; padding-top:1px; font-size:13px; margin-top:1px; vertical-align:middle">';
						echo '<input type="button" onclick ='.'"'.'return prikaziPopUp('.$komentar['idKomentar'].')" id="btnSearch" class="button" value="Prijavi" style="padding-bottom:1px; padding-top:1px; font-size:13px; margin-top:1px; vertical-align:middle"></p></td></tr></table></br>';
					}
				}
				
				?>
            </div>
        </div>

      	 <?php
	 if ($greska==0){
    echo '<ul id="content-side">
        <li id="podaci" style="height:100px">
        	<div class="dashes-top"></div>
            <div class="dashes-bottom"></div>
            <font size="+1">';

			 echo "Naziv: $naziv";
			 	 if ($tipKorisnika == "A") echo '<input type="button" onclick ='.'"'.'return ukloniPoklon('.$idPoklona.')" id="btnSearch" class="button" value="Ukloni" style="padding-bottom:1px; padding-top:1px; font-size:13px; margin-top:10px; vertical-align:middle; float:right">';
				 echo"</br>Cena: $cena</br></br>";
			 if (isset($_SESSION['ocenjivao'])||$tipKorisnika !="P")
			 {
				 if ( $tipKorisnika !="P" || $_SESSION['ocenjivao'] == $idPoklona )
				 echo '<center><img src="images/plus.png" alt="Plus" />'.$plus.':'.$minus.'<img src="images/minus.png" alt="Minus" /></center>';
			 	else
				  	echo '<center><img src="images/plus.png" style="cursor:pointer;" onClick="oceni('.$idPoklona.','.$idKorisnika.')"alt="Plus" />'.$plus.':'.$minus.'<img src="images/minus.png" style="cursor:pointer;" onClick="oceni('.(0-$idPoklona).','.$idKorisnika.')"alt="Minus" /></center>';
			 }
			 else
        	echo '<center><img src="images/plus.png" style="cursor:pointer;" onClick="oceni('.$idPoklona.','.$idKorisnika.')"alt="Plus" />'.$plus.':'.$minus.'<img src="images/minus.png" style="cursor:pointer;" onClick="oceni('.(0-$idPoklona).','.$idKorisnika.')" alt="Minus" /></center>';
			
			 
           echo '
           </font>
            </li>
            <li style="height:200px">
            <div class="dashes-top"></div>
            <div class="dashes-bottom"></div>';
           
		   
		    if ( isset($redK['idKorisnik'])) 
			{
                        echo'<a href="Profil.php?id='.$redK["idKorisnik"].'">';
				echo '<center>DODAO</br><img src="phpscripts/prikazisliku.php?id='. $redK["idSlika"]. '" style="max-height: 110px; max-width: 150px" /></center></br>';
				echo '<center><font size = "2">'.$redK["ime"].'</a></font></center>';

			}
		   
		  
            echo"</li>
            </ul>";}
             ?>
    <div class="popup-container" id="popUp"   style="visibility:hidden">
            <div class="popup"  style="position:fixed; top:50%; left:30%; width:415px">
            	<div id="dashes-top" style="display:block; width:90%"></div>
                <div id="dashes-bottom" style="display:block; width:90%"></div>
                <textarea id="poljeZaPrijavu" cols="50" rows="5">Tekst prijave
                </textarea>
               <input style="visibility:hidden"/> <a href="#" class="button" onclick="posaljiPrijavu()" style="float:right">Posalji</a>
            </div>
            </div>
        </div>
    </div>
    
</div>

</body>
</html> 